package org.wanda.pv.service.business.impl;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.stereotype.Service;
import org.wanda.pv.model.business.MarkFileRe;
import org.wanda.pv.service.BaseServiceImpl;
import org.wanda.pv.service.business.MarkFileReService;

import java.util.List;

/**
 * @author lxy
 * Created by 2018/12/19 11:14
 */
@Service
public class MarkFileReServiceImpl extends BaseServiceImpl<MarkFileRe> implements MarkFileReService {
	public MarkFileReServiceImpl(Dao dao) {
		super(dao);
	}

	@Override
	public void copyOldVersionMarksToNew(Long oldDrawingId, Long newDrawingId)throws Exception {
		/*
			首先根据老版本的文件id查询出所有的关联标注，然后添加到新的文件上。
		    只操作关联关系，并不对标注实体进行操作
		 */
		List<MarkFileRe> markFileReList=dao().query(MarkFileRe.class, Cnd.where("hy_drawing_id","=",oldDrawingId));
		if(markFileReList != null){
			markFileReList.forEach(markFileRe -> {
				// 因为是从老版本复制过来的，所以，它的 CurrentVersion  是 false ,然后重新插入
				markFileRe.setDrawingId(newDrawingId);
				markFileRe.setCurrentVersion(false);
				dao().insert(markFileRe);
			});
		}
	}
}
